package l1j.opqlo.NewSystem;

import java.sql.SQLException;
import java.util.Timer;
import java.util.TimerTask;

import l1j.opqlo.Place;
import l1j.server.server.utils.SystemUtil;

/** 排行榜定時重新加載 */
public class PlaceReLoad extends TimerTask {

	private static int _time;
	private static long _startTime;

	public PlaceReLoad(final int time) {
		_time = time * 1000;
	}

	public void begin() {
		final Timer timer = new Timer(true);
		timer.scheduleAtFixedRate(this, _time, _time); // 延遲時間30分鐘
	}

	@Override
	public void run() {
		try {
			_startTime = System.currentTimeMillis();
			System.out.println("※-----系統自動更新排名-----※\n(開始)記憶體:"
					+ SystemUtil.getUsedMemoryMB() + " MB");
			Place.getInstance().load();
			System.out.println("(結束)記憶體:" + SystemUtil.getUsedMemoryMB()
					+ " MB 總花費時間: " + (System.currentTimeMillis() - _startTime)
					+ "ms\n※-----系統自動更新排名-----※");

		} catch (final SQLException e) {
			System.out.println("錯誤1");
			e.printStackTrace();
			this.cancel();
		} catch (final InterruptedException e) {
			// TODO Auto-generated catch block
			System.out.println("錯誤2");
			e.printStackTrace();
			this.cancel();
		}

	}

}
